package com.eastfair.tag.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 标签表
 * </p>
 *
 * @author zjn
 * @date 2022-03-18
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "TagTypeEnum", description = "标签类型 #{classify:分类; node:标签-枚举")
public enum TagTypeEnum implements BaseEnum {

    /**
     * CLASSIFY="分类"
     */
    CLASSIFY("分类"),
    /**
     * NODE="标签"
     */
    NODE("标签"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static TagTypeEnum match(String val, TagTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static TagTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(TagTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "CLASSIFY,NODE", example = "CLASSIFY")
    public String getCode() {
        return this.name();
    }

}
